package com.ruimei.service.impl;

import com.ruimei.mapper.BookMapper;
import com.ruimei.service.IBookService;
import com.ruimei.util.ResultMap;
import com.ruimei.vo.TeacherBookVo;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

@Service
public class IBookServiceImpl
  implements IBookService
{
  @Resource
  private BookMapper book;
  
  @Cacheable(value={"myCache"}, key="'getBooks'+ #classId")
  @Override
  public ResultMap getBooks(String classId)
  {
    ResultMap ret = new ResultMap(this.book.selectAllParent(classId));
    return ret;
  }
  
  @Cacheable(value={"myCache"}, key="'getTeacherBook'+ #classId")
  @Override
  public ResultMap getTeacherBook(String classId)
  {
	  List<TeacherBookVo> vo = new ArrayList<TeacherBookVo>();
	  List<String> list = book.selectAllStudentByClassId(classId);
	  for (int i = 0; i < list.size(); i++) {
		  TeacherBookVo tv =  this.book.selectTeacherBook(list.get(i));
		  if(tv != null) {
			  vo.add(tv);
		  }
	  
	}
	  
    ResultMap ret = new ResultMap(vo);
    return ret;
  }
}


